#include "uart.h"

u8 tx_buf[18];
u8 tx_index        = 0;
u8 tx_len          = 0;

u8          is_in_uart_send = 0;

void
uart_init(u8 baud)
{
        TMOD |= 0x20;
        SCON = 0x50;
        PCON = 0x80;
        TH1  = baud;
        TL1  = baud;
        ES   = 1;
        EA   = 1;
        TR1  = 1;
}

void
uart_send(void)
{
        while (tx_len != 0)
                ; // 等待完成
        EA   = 0; // 关中断
        u8 i = 0;
        while (tx_buf[i] && i < 16)
                i++;
        tx_buf[i++] = '\r';
        tx_buf[i++] = '\n';
        tx_len      = i;
        tx_index    = 0;
        SBUF        = tx_buf[tx_index++];
        EA          = 1; // 开中断
}
